//
//  LaunchViewController.m
//  第六组电影项目
//
//  Created by 6-1 on 14-7-3.
//  Copyright (c) 2014年 www.skedu.com.cn北京尚德智远科技有限公司. All rights reserved.
//

#import "LaunchViewController.h"
#import "MainViewController.h"

@interface LaunchViewController ()

@end

@implementation LaunchViewController

-(void)loadView{
    UIImageView *view=[[UIImageView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
    view.image = [UIImage imageNamed:@"launch"];
    self.view=view;
    [self setProperty];
    [self loadLogoView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self showLogoView];
	// Do any additional setup after loading the view.
}

-(void)setProperty{
    _count=18;
    _maxRow=7;
    _height= kDeviceHeight/7;
}

-(void)loadLogoView{
    int x=0,y=0;
    CGFloat width = kDeviceWidth/4.0;
    _logoArray=[NSMutableArray arrayWithCapacity:_count];
    for (int index=0; index<_count; index++) {
        UIImageView *logo=[[UIImageView alloc]init];
        logo.alpha=0;
        NSString *imgname=[NSString stringWithFormat:@"%i",index+1];
        logo.image=[UIImage imageNamed:imgname];
        [self.view addSubview:logo];
        
        logo.width=width;
        logo.height=_height;
        logo.left+=x;
        logo.top+=y;
        
        if (index<3) {
            x+=logo.width;
        }
        else if (index>=3&&index<_maxRow+2){
            y+=logo.height;
        }
        else if (index>=_maxRow+2&&index<_maxRow+5){
            x-=logo.width;
        }
        else {
            y-=logo.height;
        }
        
        [_logoArray addObject:logo];
    }
}

static int i=0;
-(void)showLogoView{
    if (i>=_count) {
        [[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
        MainViewController *mainVC=[[MainViewController alloc]init];
        self.view.window.rootViewController=mainVC;
        return;
    }
    
    UIImageView *logo=_logoArray[i];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    logo.alpha=1;
    [UIView commitAnimations];
    
    [self performSelector:@selector(showLogoView) withObject:nil afterDelay:0.1];
    i++;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
